package com.cy.pj.goods.dao;

import com.cy.pj.goods.pojo.Goods;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@Repository
public class GoodsDaoImpl implements GoodsDao{
    /*
     * 底层使用的是DefaultSqlSession(线程不安全)
     * 外层套了一层SqlSessionTemplate(线程安全)
     * 装饰模式
     */
    @Autowired
    SqlSession session;
    @Override
    public List<Goods> findGoods() {
        System.out.println("===手写===");
        //命名空间
        String statement="com.cy.pj.goods.dao.GoodsDao.findGoods";
        return session.selectList(statement);
    }

    @Override
    public int deleteById1(Integer id) {
        String statement="com.cy.pj.goods.dao.GoodsDao.deleteById1";
        return session.delete(statement);
    }

    @Override
    public int deleteById2(Integer... ids) {
        String statement="com.cy.pj.goods.dao.GoodsDao.deleteById2";
        Map map=new HashMap();
        map.put("ids", ids);
        return session.delete(statement,map);
    }
}
